//
//  BIZCCLiveRequestTool.m
//  biz
//
//  Created by zhangfuwei on 2017/3/28.
//  Copyright © 2017年 jieshuibao. All rights reserved.
//

#import "BIZCCLiveRequestTool.h"
#import "CCSDK/RequestData.h"

//static NSString *const kDefaultUserID = @"A0123BC413D6FBAE";

@interface BIZCCLiveRequestTool ()<RequestDataDelegate>

@end

@implementation BIZCCLiveRequestTool{
    
    BIZCCLiveRequestSuccessfulBlock _successBlock;
    BIZCCLiveRequestFailedBlock _failedBlock;

}

+(instancetype)shareManager {
    
    static id instance;
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instance = [[self alloc] init];
    });
    
    return instance;

}

- (void)requestWithUserId:(NSString *)userId RoomId:(NSString *)roomId ViewerName:(NSString *)name ViewerToken:(NSString *)token successBlock:(BIZCCLiveRequestSuccessfulBlock)successfulBlock failBlock:(BIZCCLiveRequestFailedBlock)failBlock {
    
//    RequestData *requestData = [[RequestData alloc] initOnlyLoginWithUserId:userId RoomId:roomId ViewerName:name ViewerToken:token security:YES];
    
    PlayParameter *playParm = [[PlayParameter alloc] init];
    playParm.userId = userId;
    playParm.roomId = roomId;
    playParm.viewerName = name;
    playParm.token = token;
    playParm.security = YES;
    playParm.viewercustomua = @"viewercustomua";

    RequestData *requestData = [[RequestData alloc] initLoginWithParameter:playParm];
    requestData.delegate = self;
    _successBlock = successfulBlock;
    _failedBlock = failBlock;
    

}

-(void)requestRoomId:(NSString *)roomId ViewerName:(NSString *)name ViewerToken:(NSString *)token successBlock:(BIZCCLiveRequestSuccessfulBlock)successfulBlock failBlock:(BIZCCLiveRequestFailedBlock)failBlock {
    [self requestWithUserId:kCCDWPlayUserID RoomId:roomId ViewerName:name ViewerToken:token successBlock:successfulBlock failBlock:failBlock];
}



/**
 *	@brief  登录成功
 */
- (void)loginSucceedPlay {
    if (_successBlock) {
        _successBlock();
    }
    
}

/**
 *	@brief  登录失败
 */
-(void)loginFailed:(NSError *)error reason:(NSString *)reason {
    
    if (_failedBlock) {
        NSString *str = nil;
        if(reason != nil) {
            str = reason;
        } else {
            str = [error localizedDescription];
        }
        _failedBlock(str);
    }    
}

@end
